package com.ibm.cps.newmessage;

import java.util.HashMap;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.KryoSerializable;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ibm.util.JSONUtility;
import com.ibm.util.exception.CPSException;

public class SerializableDataSourceMetadata extends BasicDataSourceMetadata
		implements KryoSerializable {

	public SerializableDataSourceMetadata() {

	}

	public SerializableDataSourceMetadata(String input) throws CPSException {
		this(JSONUtility.fromObjectString(input));
	}

	public SerializableDataSourceMetadata(ObjectNode node) throws CPSException {
		super(node);
	}

	@Override
	public void write(Kryo kryo, Output output) {
		output.writeString(tenantid);
		output.writeString(dataSourceName);
		output.writeString(input);
		kryo.writeObject(output, key2value);
		output.writeString(schemaString);
		output.writeString(schemaid);
		output.writeString(schemaFormat);
		output.writeString(type);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void read(Kryo kryo, Input input) {
		this.tenantid = input.readString();
		this.dataSourceName = input.readString();
		this.input = input.readString();
		this.key2value = kryo.readObject(input, HashMap.class);
		this.schemaString = input.readString();
		this.schemaid = input.readString();
		this.schemaFormat = input.readString();
		this.type = input.readString();
	}

}
